package com.TPNexus;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;


import com.TPNexus.dao.ProductDAO;
import com.TPNexus.model.Product;
@FacesConverter(forClass=Product.class)

public class ProductConverter implements Converter {
        @Override
    public Object getAsObject(FacesContext ctx, UIComponent component, java.lang.String value) {
        // Write code here which converts from String to Phone.
                if(value==""|value==null) {
            return null;
        }
       
       ProductDAO dao=new ProductDAO();
       return dao.getProductDetail(Long.parseLong(value));
    }

    @Override
    public String getAsString(FacesContext ctx, UIComponent component, Object value) {
        // Write code here which converts from Phone to String.
        if(value == null) {
            return "";
        }
        Product p = (Product)value;
        return String.valueOf( p.getId());
    }
}
